#include "gpio.h"
#include "Event.h"
KeyScan_pstatus ks1 = {
    .lastStatus  = 1,
    .triggerFlag = 1,
    .StatusTimer = 0};

KeyScan_pstatus ks2 = {
    .lastStatus  = 1,
    .triggerFlag = 1,
    .StatusTimer = 0};

void GPIO_Init(void)
{
    GPIOA_ModeCfg(GPIO_Pin_10, GPIO_ModeIN_PU);
    GPIOB_ModeCfg(GPIO_Pin_22, GPIO_ModeIN_PU);
    GPIOA_ModeCfg(GPIO_Pin_8, GPIO_ModeOut_PP_5mA);
    GPIOA_SetBits(GPIO_Pin_8);
}

void KeyScan(void)
{

    if (ks1.lastStatus != _KEY1_IN())
    {
        ks1.lastStatus  = _KEY1_IN();
        ks1.StatusTimer = 0;
        ks1.triggerFlag = 0;
    }
    else if (ks1.triggerFlag == 0)
    {
        ks1.StatusTimer++;
        if (ks1.StatusTimer > 50)
        {
            ks1.triggerFlag = 1;

            ks1.lastStatus ? PushEvent(ESC_K1_Up) : PushEvent(ESC_K1_Down);
        }
    }
    if (ks2.lastStatus != _KEY2_IN())
    {
        ks2.lastStatus  = _KEY2_IN();
        ks2.StatusTimer = 0;
        ks2.triggerFlag = 0;
    }
    else if (ks2.triggerFlag == 0)
    {
        ks2.StatusTimer++;
        if (ks2.StatusTimer > 50)
        {
            ks2.triggerFlag = 1;

            ks2.lastStatus ? PushEvent(ESC_K2_Up) : PushEvent(ESC_K2_Down);
        }
    }
    //  return Ks_none;
}

void KeyScanTask(void)
{

    KeyScan();
}